package com.learn.thread;

/**
 * 同步锁继承与实现方式测试对比
 */
public class WindowTest {

    public static void main(String[] args) {
//        Windows w1 = new Windows();
//        Windows w2 = new Windows();
//        Windows w3 = new Windows();
        Windows1 w = new Windows1();
        Thread w1 = new Thread(w);
        Thread w2 = new Thread(w);
        Thread w3 = new Thread(w);

        w1.start();
        w2.start();
        w3.start();
    }
}

class Windows extends Thread{

    public static int num=100;
    @Override
    public void run() {
        while (num>0){
            piao();
        }
    }

    public synchronized static void piao(){
        if (num>0){
            System.out.println(Thread.currentThread().getName()+ ":" +num);
            num--;
        }

    }
}

class Windows1 implements Runnable{

    public int num = 100;

    public void run() {
        while (num>0){
            piao();
        }
    }

    public synchronized void piao(){
        if (num>0){
            System.out.println(Thread.currentThread().getName()+ ":" +num);
            num--;
        }
    }

}